07. Binary Classification Demo
Cd13639 C1 L4 DEMO 2 V1
Using Logistic Regression to Predict Stock Market Returns
Understand how logistic regression is applied to forecasting one-day stock market returns by converting continuous returns into binary variables.
Methodology Overview:
Library Importation and Setup
- Essential libraries include function library,
StandardScaler, andstatsmodels API. - Historical stock prices are imported and converted to returns.
- Essential libraries include function library,
Data Preparation
- Convert continuous forward-looking returns into binary targets.
- Split data into train (70%) and test (30%) sets.
- Features derived from past returns; the target is the binary variable.
Data Normalization
- Normalize data using
StandardScaler. - Apply scaling only to training data to avoid bias.
- Normalize data using
Logistic Regression Model Creation
- Add a constant to datasets for regression.
- Fit the logistic regression model to the training data.
- Observe regression output and coefficient signs.
Predictive Analysis and Strategy Formation
- Use trained model to predict returns on the test set.
- Formulate a trading strategy based on prediction probabilities.
- Evaluate strategy performance against the market, noting strengths like a higher Sharpe Ratio.
Explore a smoother investment strategy during down markets by leveraging logistic regression insights.